//
//  YLAMYGendderCell.swift
//  Your Lover AI
//
//  Created by 阿忠 on 2024/6/22.
//

import Foundation
import UIKit

class YLAMYGendderCell: UITableViewCell {
    
    
    //背景
    lazy var backVc: UIView = {
        let view = UIView()
        view.backgroundColor = .clear
        view.layer.cornerRadius = 10.0 // 设置圆角半径为10.0
        view.layer.masksToBounds = true
        return view
    }()
    
    //修改图
    lazy var editImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "set_edit"))
        return image
    }()
    
    //提示
    lazy var titleLab: UILabel = {
        let lab = UILabel()
        lab.text = "Your gender"
        lab.textColor = UIColor(hex: "FFFFFF")
        lab.font = UIFont.systemFont(ofSize: 15)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        return lab
    }()
    
    //女生背景
    lazy var femaleView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: "7157FF")
        view.layer.cornerRadius = 10.0 // 设置圆角半径为10.0
        view.layer.masksToBounds = true
        return view
    }()
    
    //女生图
    lazy var femaleImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "set_female"))
        return image
    }()
    
    //女生选择图
    lazy var femaleSelImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "set_sel"))
        return image
    }()
    
    //女生提示
    lazy var femaleLab: UILabel = {
        let lab = UILabel()
        lab.text = "Female"
        lab.textColor = UIColor(hex: "FFFFFF")
        lab.font = UIFont.systemFont(ofSize: 17)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        return lab
    }()
    
    //女生选择
    lazy var femaleBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.backgroundColor = .clear
        button.addTarget(self, action: #selector(femaleClick), for: .touchUpInside)
        return button
    }()
    
    //男生背景
    lazy var maleView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: "7157FF")
        view.layer.cornerRadius = 10.0 // 设置圆角半径为10.0
        view.layer.masksToBounds = true
        return view
    }()
    
    //男生图
    lazy var maleImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "set_male"))
        return image
    }()
    
    //男生提示
    lazy var maleLab: UILabel = {
        let lab = UILabel()
        lab.text = "Male"
        lab.textColor = UIColor(hex: "FFFFFF")
        lab.font = UIFont.systemFont(ofSize: 17)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        return lab
    }()
    
    //男生选择图
    lazy var maleSelImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "set_sel"))
        return image
    }()
    
    //女生选择
    lazy var maleBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.backgroundColor = .clear
        button.addTarget(self, action: #selector(maleClick), for: .touchUpInside)
        return button
    }()
    
    //其他背景
    lazy var otherView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(hex: "7157FF")
        view.layer.cornerRadius = 10.0 // 设置圆角半径为10.0
        view.layer.masksToBounds = true
        return view
    }()
    
    //其他提示
    lazy var otherLab: UILabel = {
        let lab = UILabel()
        lab.text = "Other"
        lab.textColor = UIColor(hex: "FFFFFF")
        lab.font = UIFont.systemFont(ofSize: 17)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        return lab
    }()
    
    //其他选择图
    lazy var otherSelImg: UIImageView = {
        let image = UIImageView(image: UIImage(named: "set_sel"))
        return image
    }()
    
    //女生选择
    lazy var otherBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.backgroundColor = .clear
        button.addTarget(self, action: #selector(otherClick), for: .touchUpInside)
        return button
    }()
    
    //名字
    lazy var nameLab: UILabel = {
        let lab = UILabel()
        lab.text = "Your nickname"
        lab.textColor = UIColor(hex: "FFFFFF")
        lab.font = UIFont.systemFont(ofSize: 17)
        lab.textAlignment = .left
        lab.numberOfLines = 0
        return lab
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .clear
        contentView.addSubview(backVc)
        backVc.addSubview(titleLab)
        backVc.addSubview(femaleView)
        femaleView.addSubview(femaleImg)
        femaleView.addSubview(femaleLab)
        femaleView.addSubview(femaleSelImg)
        femaleView.addSubview(femaleBtn)
        backVc.addSubview(maleView)
        maleView.addSubview(maleImg)
        maleView.addSubview(maleLab)
        maleView.addSubview(maleSelImg)
        maleView.addSubview(maleBtn)
        backVc.addSubview(otherView)
        otherView.addSubview(otherLab)
        otherView.addSubview(otherSelImg)
        otherView.addSubview(otherBtn)
        initUI()
    }

    
    func initUI()
    {
        backVc.snp.makeConstraints { make in
            make.left.equalTo(0)
            make.right.equalTo(0)
            make.top.equalTo(0)
            make.bottom.equalTo(0)
        }
        
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.top.equalTo(21)
            make.height.equalTo(15)
        }
        
        let screenSize = (UIScreen.main.bounds.size.width - 48 ) / 2
        
        femaleView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.top.equalTo(titleLab.snp.bottom).offset(15)
            make.height.equalTo(56)
            make.width.equalTo(screenSize)
        }
        
        femaleImg.snp.makeConstraints { make in
            make.left.equalTo(31)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(29)
        }
        
        femaleLab.snp.makeConstraints { make in
            make.left.equalTo(femaleImg.snp.right).offset(5)
            make.centerY.equalToSuperview()
        }
        
        femaleSelImg.snp.makeConstraints { make in
            make.top.right.equalToSuperview()
            make.width.equalTo(22)
            make.height.equalTo(20)
        }
        
        femaleBtn.snp.makeConstraints { make in
            make.left.top.right.bottom.equalToSuperview()
        }
        
        maleView.snp.makeConstraints { make in
            make.right.equalTo(-16)
            make.top.equalTo(femaleView)
            make.height.equalTo(56)
            make.width.equalTo(screenSize)
        }
        
        maleImg.snp.makeConstraints { make in
            make.left.equalTo(31)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(29)
        }
        
        maleLab.snp.makeConstraints { make in
            make.left.equalTo(maleImg.snp.right).offset(5)
            make.centerY.equalToSuperview()
        }
        
        maleSelImg.snp.makeConstraints { make in
            make.top.right.equalToSuperview()
            make.width.equalTo(22)
            make.height.equalTo(20)
        }
        
        maleBtn.snp.makeConstraints { make in
            make.left.top.right.bottom.equalToSuperview()
        }
        
        otherView.snp.makeConstraints { make in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.top.equalTo(femaleView.snp.bottom).offset(16)
            make.height.equalTo(56)
        }
        
        otherLab.snp.makeConstraints { make in
            make.centerX.centerY.equalToSuperview()
        }
        
        otherSelImg.snp.makeConstraints { make in
            make.top.right.equalToSuperview()
            make.width.equalTo(22)
            make.height.equalTo(20)
        }
        
        otherBtn.snp.makeConstraints { make in
            make.left.top.right.bottom.equalToSuperview()
        }
      
        femaleView.layer.borderWidth = 3
        femaleView.layer.borderColor = UIColor.white.cgColor
        maleSelImg.isHidden = true
        otherSelImg.isHidden = true
    }
    
    
    @objc func femaleClick(){
        
        femaleView.layer.borderWidth = 3
        femaleView.layer.borderColor = UIColor.white.cgColor
        femaleSelImg.isHidden = false
        
        maleView.layer.borderWidth = 3
        maleView.layer.borderColor = UIColor.clear.cgColor
        maleSelImg.isHidden = true
        
        otherView.layer.borderWidth = 3
        otherView.layer.borderColor = UIColor.clear.cgColor
        otherSelImg.isHidden = true
    }
    
    @objc func maleClick(){
        
        femaleView.layer.borderWidth = 3
        femaleView.layer.borderColor = UIColor.clear.cgColor
        femaleSelImg.isHidden = true
        
        maleView.layer.borderWidth = 3
        maleView.layer.borderColor = UIColor.white.cgColor
        maleSelImg.isHidden = false
        
        otherView.layer.borderWidth = 3
        otherView.layer.borderColor = UIColor.clear.cgColor
        otherSelImg.isHidden = true
    }
    
    @objc func otherClick(){
        
        femaleView.layer.borderWidth = 3
        femaleView.layer.borderColor = UIColor.clear.cgColor
        femaleSelImg.isHidden = true
        
        maleView.layer.borderWidth = 3
        maleView.layer.borderColor = UIColor.clear.cgColor
        maleSelImg.isHidden = true
        
        otherView.layer.borderWidth = 3
        otherView.layer.borderColor = UIColor.white.cgColor
        otherSelImg.isHidden = false
    }
    
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

